package com.wuheng.smartlock;

import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;

public class GyroListener implements SensorEventListener {

	private final float nanoSecondsPersecond = 1.0f / 100000000.0f;
	private long lastTime = 0;
	private boolean state = false;

	@Override
	public void onAccuracyChanged(Sensor sensor, int accuracy) {
		// TODO 自动生成的方法存根

	}

	@Override
	public void onSensorChanged(SensorEvent event) {
		// TODO 自动生成的方法存根
		if (lastTime != 0) {
			float[] values = event.values;
			final float dT = ((event.timestamp - lastTime) * nanoSecondsPersecond);
			state = (values[0] * dT > 1);
			// Log.d("wuheng", "state = " + state);
		}
		lastTime = event.timestamp;
	}

	public boolean getState() {
		return state;
	}

}
